const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const app = express();
const axios = require("axios");
axios.defaults.baseURL = 'http://www.mianded.top:8081';
const PORT = process.env.APP_PORT || 32148;
const HOST = process.env.APP_HOST || '0.0.0.0';
const cookieParser = require('cookie-parser');
const session=require('express-session')
app.use(cookieParser());
app.use(session({ 
    secret: 'keyboard cat',
    cookie: { maxAge: 60 * 1000 *30 *30 *24 },
    resave: false, //添加 resave 选项
    saveUninitialized: true,
}))
app.use('/static',express.static(path.join(__dirname,'./static')));
app.set("views", path.join(__dirname, "./views"));
app.set('view engine', 'html');
app.engine("html", require("express-art-template"));
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
// 配置后端接口路径
axios.defaults.baseURL = 'http://www.mianded.top:8081';
const admin = require('./router/admin');
const home = require('./router/home');
// const register = require('./router/home/register')
// 请求拦截
app.use('/admin',require('./middleware/loginGuard'))
// app.use(register)
//前台接口
app.use('/home',home);
// app.use(home)
//后台接口编写
app.use('/admin',admin);
// pkg -t node16-win-x64 app.js 
app.listen(80, ()=>{
    console.log("服务器开启,端口号：80");
})

